// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require(CONFIG.BasePath + "js/enterprise/base");
    var router = require("../hash/pageRouter");
    var footer = require("../footer/footer_gray");
    var top = require("../top/top_white");
    var nature = $("#nature").val();
	var enterpriseName;
	var businessLicence;
	var address;
	var contactAddress;
	var businessScope;
	var registeredCapital;
	var businessTimeLimit;
	var legalPerson;
	var legalIdcard;
	var legalPeriod;
	var depositBank;
	var accountHolder;
	var creditCard;
	var businessType;
	var enterpriseType;
	var	belongsEnterpriseCode;
	var proxySaleCode;
	var codeUSC;
	var certificate;
	var procurator;
	var procuratorIdcard;
	var procuratorPeriod;
	var flag = false;
	var province;
	var city;
	var district;
	var authenticationId;
	var validate = require("validate");
	var tools = require("tools");
	var databind = require("databind");
    
    var init = function(){
    	if(base.getData("sid")==null){
    		window.location="../login/login.html";
    	}
    	
    	authenticationId = base.getUrlParam("enterpriseId");
    	top.init("企业账户管理");
    	footer.init();
    	$("#head").removeClass("none");
    	$(".login").addClass("none");
    	$("#main").removeClass("none");
    	$("#footer").removeClass("none");
    	router.init();
   // 	inquireEnterpriseDetail();//查询企业详情
		initEvent(); 
    };
    
	var initEvent = function(){
		$("#main").on("change", "#creditCard", function(){
			var bn = tools.getBankName($(this).val());
			if (bn == ""){
				alert("未知开户行！");
			} else {
				$("#depositBank").val(bn);
			}
		});
		
		$("#main").on("change", "#legalIdcard", function(){
			var promptString = validate.isIdCard($(this), "请输入正确的身份证号码!");
			if ("" != promptString) {
				base.alert(2, promptString)
			} 
		});
		
//		layer.tips(tools.formatCurrency($("input[name=registeredCapital]").val()) + '(' + tools.changeMoneyToChinese($("input[name=registeredCapital]").val()) + ')', 'input[name=registeredCapital]', {
//		  tips: [1, '#3595CC'],
//		  time: 3000
//		});
		
		$("#main").on("focus", "input[name=registeredCapital]", function(){
			var $this = $(this);
			layer.tips(tools.formatCurrency($this.val()) + '(' + tools.changeMoneyToChinese($("input[name=registeredCapital]").val()) + ')', 'input[name=registeredCapital]', {
			  tips: [1, '#3595CC'],
			  time: 3000
			});
		});
		
		$("#main").on("change", "input[name=registeredCapital]", function(){
			var $this = $(this);
			layer.tips(tools.formatCurrency($this.val()) + '(' + tools.changeMoneyToChinese($("input[name=registeredCapital]").val()) + ')', 'input[name=registeredCapital]', {
			  tips: [1, '#3595CC'],
			  time: 3000
			});
		});
		
		$('.bankInfo').card({
            container: $('.card-wrapper'),
            formSelectors: {
            	numberInput: "input[name=creditCard]",
            	nameInput: 'input[name="accountHolder"]',
			    expiryInput: 'input[name="expiry"]',
			    cvcInput: 'input[name="cvc"]'
            }
        });
		//认证提交
		$("#main").on("click", ".next", function(){
			databind.submitDom($("#main"), function(data){//获取div的id值通过HTML中的action="informationCheck"传到后台
	                if (data.status == 200) {
	                	base.alert(1, "提交成功！");
						router.route("account/account.html");
	                } else {
	                	base.alert(1, "提交失败！");
						router.route("account/account.html");
	                }
		  	});
		});
		
//		单位类型 nature 
//		企业名 enterpriseName 
//		单位注册号 businessLicence 
//		营业执照所在地 address
//		联系地址 contactAddress
//		经营范围 businessScope
//		注册资金 registeredCapital
//		营业期限 businessTimeLimit
//		法定代表人姓名 legalPerson
//		身份证号 legalIdcard
//		证件有效期 legalPeriod
//		开户行 depositBank
//		开户名称 accountHolder
//		银行卡号 creditCard

		databind.fillInput1($("#main"), {action: "inquireCurrentEnterpriseDetail.json"}, function(data){
			$("select[name=city]").html("<option>"+data.datas[0].city+"</option>");
			$("select[name=district]").html("<option>"+data.datas[0].district+"</option>");
		});

    };
	
    return {
        init:init
    };
});